import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from 'vue';
import {Tag} from 'ant-design-vue';
import {TaskCenterList} from "/@/api/taskCenter/taskCenter";
import {getTaskTypeList} from "/@/api/taskCenter/taskType";

const taskTypeList = await getTaskTypeList();
console.log('taskTypeList', taskTypeList)
export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 50,
    align: 'center',
  },
  {
    title: '姓名',
    dataIndex: 'fname',
    width: 100,
    align: 'center',
  },
  {
    title: '工号',
    dataIndex: 'fnumber',
    width: 100,
    align: 'center',
  },
  {
    title: '职称',
    dataIndex: 'type',
    width: 100,
    align: 'center',
  },
  {
    title: '部门',
    dataIndex: 'class',
    width: 180,
    align: 'center',
  },
  {
    title: '完成状态',
    dataIndex: 'complete',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const status_name = ['未完成', '部分完成', '超量完成'];
      const color_name = ['red', 'blue', 'green'];
      return h(Tag, {color: color_name[record.complete - 1]}, () => status_name[record.complete - 1]);
    },
  },
  //====
  {
    title: '教学课时',
    dataIndex: 'jxks',
    width: 160,
    align: 'center',
  },
  {
    title: '教学课时-超量',
    dataIndex: 'jxkscl',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const max = record.jxks_full_mark;
      return record.jxks - max <= 0 ? 0 : (record.jxks - max).toFixed(2);
    },
  },
  {
    title: '教科研积分',
    dataIndex: 'jkyjf',
    width: 100,
    align: 'center',
  },
  {
    title: '教科研积分-超量',
    dataIndex: 'jkyjfcl',
    width: 150,
    align: 'center',
    customRender: ({record}) => {
      const max = record.jkyjf_full_mark;
      return record.jkyjf - max <= 0 ? 0 : (record.jkyjf - max).toFixed(2);
    },
  },
  {
    title: '教科研建设积分',
    dataIndex: 'jkyjsjf',
    width: 160,
    align: 'center',
  },
  {
    title: '教科研建设积分-超量',
    dataIndex: 'jkyjsjfcl',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const max = record.jkyjsjf_full_mark;
      return record.jkyjsjf - max <= 0 ? 0 : (record.jkyjsjf - max).toFixed(2);
    },
  },

  {
    title: '管理与公共服务积分',
    dataIndex: 'glyggfwjf',
    width: 180,
    align: 'center',
  },
  {
    title: '管理与公共服务积分-超量',
    dataIndex: 'glyggfwjfcl',
    width: 200,
    align: 'center',
    customRender: ({record}) => {
      const max = record.glyggfwjf_full_mark;
      return record.glyggfwjf - max <= 0 ? 0 : (record.glyggfwjf - max).toFixed(2);
    },
  },
  {
    title: '备注',
    dataIndex: 'tips',
    width: 160,
    align: 'center',
  },

  {
    title: '是否认证',
    dataIndex: 'authentication',
    width: 80,
    customRender: ({record}) => {
      const status = record.authentication;
      const color = status === 1 ? 'green' : 'red';
      const text = status === 1 ? '是' : '否';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '创建时间',
    dataIndex: 'create_time',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'fname',
    label: '教师名称',
    component: 'Input',
    colProps: {span: 8},
  },
  {
    field: 'fnumber',
    label: '员工号',
    component: 'Input',
    colProps: {span: 8},
  },
  {
    field: 'complete',
    label: '完成情况',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '未完成',
          value: 1,
        },
        {
          label: '部分完成',
          value: 2,
        },
        {
          label: '超量完成',
          value: 3,
        },
      ]
    },
    colProps: {span: 8},
  },
];

//新增弹窗form字段
export const formSchema: FormSchema[] = [
  {
    label: 'ID',
    field: 'id',
    component: 'Input',
    labelWidth: '150px',
    defaultValue: 0,
    show: false,
  },
  {
    field: 'fname',
    label: '教师姓名',
    component: 'Input',
    labelWidth: '150px',
    required: true,
  },
  {
    field: 'fnumber',
    label: '员工号',
    component: 'Input',
    labelWidth: '150px',
    required: true,
  },
  {
    label: '职称',
    field: 'type',
    component: 'Input',
    labelWidth: '150px',
    defaultValue: '',
    required: false,
  },
  {
    label: '部门',
    field: 'class',
    component: 'Input',
    labelWidth: '150px',
    defaultValue: '',
    required: false,
  },
  {
    field: 'jxks',
    label: '教学课时',
    component: 'InputNumber',
    labelWidth: '150px',
    defaultValue: 0,
    show: true,
    required: true,
  },
  {
    field: 'jkyjf',
    label: '教科研积分',
    component: 'InputNumber',
    labelWidth: '150px',
    defaultValue: 0,
    show: true,
    required: true,
  },
  {
    field: 'jkyjsjf',
    label: '教科研建设积分',
    labelWidth: '150px',
    component: 'InputNumber',
    defaultValue: 0,
    show: true,
    required: true,
  },
  {
    field: 'glyggfwjf',
    label: '管理与公共服务积分',
    labelWidth: '150px',
    component: 'InputNumber',
    defaultValue: 0,
    show: true,
    required: true,
  },
  {
    field: 'tips',
    label: '备注',
    labelWidth: '150px',
    component: 'InputTextArea',
    defaultValue: '',
    show: true,
  },
  {
    field: 'authentication',
    label: '是否已认证',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    labelWidth: '150px',
    componentProps: {
      options: [
        {label: '是', value: 1},
        {label: '否', value: 0},
      ],
    },
    required: true,
    show: false,
  },
];


//为用户追加任务弹窗form字段
export const taskFormSchema: FormSchema[] = [
  {
    label: 'ID',
    field: 'id',
    component: 'Input',
    defaultValue: 0,
    show: false,
  },
  {
    label: '追加任务',
    field: 'class',
    component: 'ApiSelect',
    componentProps: {
      api: TaskCenterList,
      resultField: 'result.data',
      labelField: 'title',
      valueField: 'id',
    },
    required: true,
  },

];
